/* 
 * File:   Vector.h
 * Author: gilvolpe
 *
 * Created on June 8, 2013, 9:08 AM
 */

#ifndef VECTOR_H
#define	VECTOR_H

template <typename T>
class Vector {
public:

    Vector(){
        this->x = 0;
        this->y = 0;
        this->z = 0;
    }
    
    Vector(Vector start, Vector end) {
        this->x = end.x - start.x;
        this->y = end.y - start.y;
        this->z = end.z - start.z;
        
        this->normalize();
    }

    void setPosition(T x,T y,T z){
        this->x = x;
        this->y = y;
        this->z = z;
    }    
    
    T lenght() {
        return (T) (sqrt(this->x * this->x + this->y * this->y + this->z * this->z));
    }

    void normalize() {
        T l_length;

        l_length = this->lenght();
        if (l_length == 0) l_length = 1;

        this->x /= l_length;
        this->y /= l_length;
        this->z /= l_length;
    }

    T scalarProdcut(Vector v) {
        return (this->x * v.x + this->y * v.y + this->z * v.z);
    }

    Vector vectorProduct(Vector v) {

        Vector normal;

        normal.x = (this->y * v.z) - (this->z * v.y);
        normal.z = (this->z * v.x) - (this->x * v.z);
        normal.y = (this->x * v.y) - (this->y * v.x);
        
        normal.x *= -1;
        
        return normal;
    }
    
    T getX() const {
        return x;
    }

    T getY() const {
        return y;
    }

    T getZ() const {
        return z;
    }


private:
    T x, y, z;
};


#endif	/* VECTOR_H */

